package vip.xiaonuo.smzq.modular.kcl.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import vip.xiaonuo.smzq.modular.kcl.entity.Cxh;
import vip.xiaonuo.smzq.modular.kcl.mapper.CxhMapper;
import vip.xiaonuo.smzq.modular.kcl.service.ICxhService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 采选环 服务实现类
 *
 * @author eomer
 * @since 2024-02-22
 */
@Service
public class CxhServiceImpl extends ServiceImpl<CxhMapper, Cxh> implements ICxhService {

    @Resource
    private CxhMapper cxhMapper;

    @Override
    public Page<Cxh> page(Cxh cxh) {
        QueryWrapper<Cxh> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Override
    public Cxh getCxh(String kqbm, Integer djflbm, Integer nd) {
        Cxh cxh= new Cxh();
        try{
            QueryWrapper<Cxh> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("kqbh", kqbm).eq("nd", nd).eq("djflbh", djflbm);
            cxh= cxhMapper.selectOne(queryWrapper);
        }catch (Exception e){
            e.printStackTrace();
        }


        return cxh;
    }

    /**
     * 添加采选环
     * @param cxh
     * @return
     */
    @Override
    public int addCxh(Cxh cxh,String kqbm, Integer djflbm, Integer nd) {
        cxh.setKqbh(kqbm);
        cxh.setDjflbh(djflbm);
        cxh.setNd(nd);
        int count = 0;
        if (cxh.getPkid()!=null && cxh.getPkid().length() > 0){
            count= cxhMapper.updateById(cxh);
        }else{
            count= cxhMapper.insert(cxh);
        }
        return count;
    }

    @Override
    public List<Cxh> selectList(QueryWrapper<Cxh> queryWrappercxh) {
        return cxhMapper.selectList(queryWrappercxh);
    }
}
